/**
 * @param {number[]} nums
 * @param {number} val
 * @return {number}
 */
var removeElement = function (nums, val) {
  
    let p=0,m=nums.length-1
    for(;p<=m;){
        if(nums[p]===val){
            [nums[p],nums[m]]=[nums[m],nums[p]];
            m--
        }else{
            p++
        }
    }
    console.log(nums);
    return p

}
console.log(removeElement([4,4,0,1,0,2],0));

